package org.bim.view.drag.design.config;

import org.bim.view.drag.design.util.AliOssBootUtil;
import org.bim.view.drag.design.util.MinioUtil;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;

import javax.annotation.Resource;

/**
 * oss 配置
 */
@Configuration
@Order(-9)
public class OssConfiguration {
    @Resource
    private MinioProperties minioProperties;
    @Resource
    private AliOssProperties aliOssProperties;

    @Bean
    public void initOssBootConfiguration() {
        AliOssBootUtil.setEndPoint(aliOssProperties.getEndpoint());
        AliOssBootUtil.setAccessKeyId(aliOssProperties.getAccessKey());
        AliOssBootUtil.setAccessKeySecret(aliOssProperties.getSecretKey());
        AliOssBootUtil.setBucketName(aliOssProperties.getBucketName());
        AliOssBootUtil.setStaticDomain(aliOssProperties.getStaticDomain());
    }


    @Bean
    public void initMinio(){
        String minioUrl =minioProperties.getMinioUrl();
        if(!minioUrl.startsWith("http") &&  !minioUrl.startsWith("https")){
            minioUrl = "http://" + minioUrl;
        }
        if(!minioUrl.endsWith("/")){
            minioUrl = minioUrl.concat("/");
        }
        MinioUtil.setMinioUrl(minioUrl);
        MinioUtil.setMinioName(minioProperties.getMinioName());
        MinioUtil.setMinioPass(minioProperties.getMinioPass());
        MinioUtil.setBucketName(minioProperties.getBucketName());
    }
}
